package ru.home.documentmanager.service.impl;

import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;

import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.springframework.stereotype.Service;

import ru.home.documentmanager.service.DocXService;
import ru.home.documentmanager.service.util.DocUtil;

@Service("docXService")
public class DocXServiceImpl implements DocXService {

    @Override
    public void replacePlaceholders(InputStream in, OutputStream out,
            Map<String, String> placeholders) {
        try {
            System.out.println("replacePlaceholders");
            WordprocessingMLPackage wpml = WordprocessingMLPackage.load(in);
            DocUtil.replaceText(wpml, placeholders);
            wpml.save(out);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
